package com.yisu.kabao.manager.domain.config;


import com.alibaba.fastjson.JSON;
import io.github.xdiamond.client.annotation.OneKeyListener;
import io.github.xdiamond.client.event.ConfigEvent;
import org.springframework.beans.factory.annotation.Value;

/**
 * Created by zj on 2016/9/13.
 */
public class SystemConfig {
    @Value("${qiniu.access.key}")
    private String qiNiuAccessKey;
    @Value("${qiniu.secret.key}")
    private String qiNiuSecretKey;
    @Value("${qiniu.bucket.name}")
    private String qiNiuBucketName;
    @Value("${qiniu.image.center.host}")
    private String qiNiuImageHost;


    public String getQiNiuAccessKey() {
        return qiNiuAccessKey;
    }

    @OneKeyListener(key = "qiniu.access.key")
    public void setQiNiuAccessKey(ConfigEvent event) {
        try {
            if (event != null) {
                qiNiuAccessKey = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            qiNiuAccessKey = null;
        }
    }

    public String getQiNiuSecretKey() {
        return qiNiuSecretKey;
    }

    @OneKeyListener(key = "qiniu.secret.key")
    public void setQiNiuSecretKey(ConfigEvent event) {
        try {
            if (event != null) {
                qiNiuSecretKey = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            qiNiuSecretKey = null;
        }
    }

    public String getQiNiuBucketName() {
        return qiNiuBucketName;
    }

    @OneKeyListener(key = "qiniu.bucket.name")
    public void setQiNiuBucketName(ConfigEvent event) {
        try {
            if (event != null) {
                qiNiuBucketName = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            qiNiuBucketName = null;
        }
    }

    public String getQiNiuImageHost() {
        return qiNiuImageHost;
    }

    @OneKeyListener(key = "qiniu.image.center.host")
    public void setQiNiuImageHost(ConfigEvent event) {
        try {
            if (event != null) {
                qiNiuImageHost = String.valueOf(JSON.parseObject(event.toString()).get("value"));
            }
        } catch (Exception ex) {
            qiNiuImageHost = null;
        }
    }
}
